public class Test {
    public static void main4(String[] args) {
        System.out.println("====插入测试====");
        MyLinkedList myLinkedList = new MyLinkedList();
        myLinkedList.addFirst(1);
        myLinkedList.addFirst(2);
        myLinkedList.addFirst(3);
        myLinkedList.addLast(0);
        myLinkedList.display();
        System.out.println("============");
        myLinkedList.addIndex(0,5);
        myLinkedList.addIndex(5,1);
        myLinkedList.addIndex(1,4);
        myLinkedList.display();
        System.out.println("====删除测试====");
        myLinkedList.remove(5);
        myLinkedList.remove(1);
        myLinkedList.remove(0);
        myLinkedList.display();
        System.out.println("============");
        myLinkedList.addFirst(1);
        myLinkedList.addFirst(1);
        myLinkedList.addFirst(1);
        myLinkedList.addLast(0);
        myLinkedList.addLast(1);
        myLinkedList.addLast(1);
        myLinkedList.display();
        myLinkedList.removeAllKey(1);
        myLinkedList.display();

        myLinkedList.clear();
        myLinkedList.display();

    }


    //合并两个有序链表
    public static MyStringleList.Node mergeTwoLists(MyStringleList.Node list1, MyStringleList.Node list2) {
        MyStringleList.Node newHead = new MyStringleList.Node(1);
        MyStringleList.Node tmp = newHead;
        while (list1 != null & list2 != null) {
            if (list1.val < list2.val) {
                tmp.next = list1;
                list1 = list1.next;
            }else {
                tmp.next = list2;
                list2 = list2.next;
            }
            tmp = tmp.next;
        }
        if (list1 != null) {
            tmp.next = list1;
        }
        if (list2 != null) {
            tmp.next = list2;
        }
        return newHead.next;
    }

    public static void main2(String[] args) {
        MyStringleList myStringleList1 = new MyStringleList();
        myStringleList1.addLast(1);
        myStringleList1.addLast(6);
        myStringleList1.addLast(7);
        myStringleList1.addLast(11);
        MyStringleList myStringleList2 = new MyStringleList();
        myStringleList2.addLast(3);
        myStringleList2.addLast(4);
        myStringleList2.addLast(8);
        myStringleList2.addLast(14);
        myStringleList2.addLast(16);
        myStringleList1.display();
        myStringleList2.display();
        System.out.println("====合并有序链表====");
        myStringleList1.display(mergeTwoLists(myStringleList1.head, myStringleList2.head));
        myStringleList1.display();
        myStringleList2.display();

        System.out.println("====打印测试====");
        myStringleList2.display1(myStringleList2.head);
        System.out.println();
        myStringleList2.display(myStringleList2.head);
        myStringleList2.display2(myStringleList2.head);
        myStringleList2.display();
    }

    public static void main1(String[] args) {

        MyStringleList myStringleList = new MyStringleList();
        myStringleList.createLink();

        myStringleList.display();
        System.out.println(myStringleList.contains(33));
        System.out.println(myStringleList.size());

        System.out.println("====头插测试====");
        myStringleList.addFirst(66);
        myStringleList.display();

        System.out.println("====尾插测试====");
        myStringleList.addLast(99);
        myStringleList.display();

        System.out.println("==========");
        MyStringleList myStringleList1 = new MyStringleList();
        myStringleList1.addLast(1);
        myStringleList1.display();

        System.out.println("====测试插入====");
        MyStringleList myStringleList2 = new MyStringleList();
        myStringleList2.addFirst(1);
        myStringleList2.addFirst(0);
        myStringleList2.addLast(2);
        myStringleList2.addLast(3);
        myStringleList2.addindex(66,0);
        myStringleList2.addindex(66,myStringleList2.size());
        myStringleList2.addindex(66,3);

        try {
            myStringleList2.addindex(66,100);
        }catch (IndexOutOfException e) {
            e.printStackTrace();
        }

        myStringleList2.display();

        System.out.println("====测试删除====");
        myStringleList2.remove(66);
        myStringleList2.display();

        myStringleList2.remove(3);
        myStringleList2.display();

        myStringleList2.removeAllKey(66);
        myStringleList2.display();

        myStringleList2.addFirst(0);
        myStringleList2.addFirst(0);
        myStringleList2.addFirst(0);
        myStringleList2.addLast(0);
        myStringleList2.addLast(0);
        myStringleList2.display();

        myStringleList2.removeAllKey(0);
        myStringleList2.display();
        myStringleList2.removeAllKey(1);
        myStringleList2.display();
        myStringleList2.removeAllKey(2);
        myStringleList2.display();

        System.out.println("====逆置====");
        myStringleList.display();
        myStringleList.reverseList();
        myStringleList.display();
    }
}
